package com.mtzqc.common.init.impl

import android.app.Application
import com.didi.drouter.annotation.Service
import com.jeremyliao.liveeventbus.LiveEventBus
import com.mtzqc.common.init.InitService
import com.mtzqc.common.task.ITask

@Service(function = [InitService::class], priority = 106)
class LiveBusRegister : InitService {
    override val depName: String
        get() = "LiveBus"
    override val dependsLib: Array<Class<out ITask>>?
        get() = null
    override val depends: Array<String>?
        get() = null
    override val priority: Int
        get() = 106

    override fun executeInit(app: Application, debug: Boolean, dev: Boolean): Boolean {
        LiveEventBus
            .config()
            .setContext(app)
            // 需等到Activity重新变成激活状态，方可收到消息
            .lifecycleObserverAlwaysActive(false)
            //配置在没有Observer关联的时候是否自动清除LiveEvent以释放内存（默认值false）
            .autoClear(true)
            .enableLogger(debug)
        return true
    }
}